##search > div.container > div.search-main > div.search-result > a:nth-child(2) > section > div.job-main > div.job-title > div

import requests
from bs4 import BeautifulSoup
import re

class CodeMarket:
    def __init__(self):
        #self.URL = 'https://www.clouderwork.com/jobs/project.html'
        #self.header = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'}
        self.header = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36' }
        self.pattern1 = '/<div\s+[^>]*>([^<\/]+)<\/div>/'
        self.pattern2 = '/\d+/'
        self.pattern3 = '/<span\s+[^>]*>([^<\/]+)<\/span>/'
        #self.partner1 = "(?<=)+(?=<)"
        #self.partner2 = "\d"

    def get_project(self):
        #page = str(page)
        #html = requests.get(self.URL, params={'page': page}, headers = self.header)
        #currentPage=1&pageSize=100
        for i in range(1,2):
            URL = 'https://www.clouderwork.com/jobs/project_00_0_0_0_6_' + str(i) +'_20_0_0.html'
            #print(URL)
            html = requests.get(URL, headers = self.header)


            html.content.decode("utf-8")
            #print(html.text)

            soup = BeautifulSoup(html.text, "html.parser")
            #print(soup.get_text())
            for i in range(1,21):
                name = soup.select(' #search > div.container > div.search-main > div.search-result > a:nth-child(' +str(i)+ ') > section > div.job-main > div.job-title > div ')
                money = soup.select(' #search > div.container > div.search-main > div.search-result > a:nth-child(' +str(i)+ ') > section > div.job-main > div.job-money > span.money')
                lenth = soup.select(' #search > div.container > div.search-main > div.search-result > a:nth-child(' +str(i)+ ') > section > div.job-main > div.job-money > span.period.jg')
                time = soup.select(' #search > div.container > div.search-main > div.search-result > a:nth-child(' +str(i)+ ') > section > div.job-main > div.job-money > span.publish_at.jg')
                type = soup.select(' #search > div.container > div.search-main > div.search-result > a:nth-child(' +str(i)+ ') > section > div.job-main > div.job-keyword > span')



                #name = re.findall(name,self.pattern1)
                #money = re.findall(money,self.pattern2)
                #lenth = re.findall(lenth,self.pattern3)

                #search > div.container > div.search-main > div.search-result > a:nth-child(1) > section > div.job-main > div.job-money > span.money
                #name = soup.select(' #projectLists > div > ul > li:nth-child(2) > div.left_8 > h4 > a ')
                ##projectLists > div > ul > li:nth-child(3) > div.left_8 > h4 > a
                #//*[@id="search"]/div[3]/div[1]/div[4]/a[1]/section/div[1]/div[1]/div

                print("******************************************************************")
                print(name)
                print(money)
                print(lenth)
                print(time)
                print(type)
                print("-----------------------------------------------------------------")

if __name__ == "__main__":
    cls = CodeMarket()
    cls.get_project()